# This code is hosted on http://code.google.com/p/lenthorp/
# Freely available for use in applications, but should NOT be modified
# Email all comments to lenthorpresearch@gmail.com

import ModelParametersMod
from ModelParametersMod import *
reload(ModelParametersMod)

class PricingEngine:

    def __init__(self, modelParams):
        self.currentStatus = 0
        self.modelParams = modelParams
        self.otherParams = ModelParameters()
        self.allParams = {}
        self.storedOptimiseNames = []
        self.preComputationVariables = []
        self.numberOfPricingParams = 0
        self.targetPrice = 0
        self.targetWeight = 1

    def setUpParameters(self, pricingParamsSets, optimiseParams):
        self.currentStatus = 0
        self.pricingParamsSets = pricingParamsSets.p
        self.numberOfPricingParams = len(self.pricingParamsSets)
        self.otherParams.p.clear()
        self.setPricingParams()
        
        self.storedOptimiseNames = ['' for idx in range(len(optimiseParams.p.items()))]
        count = 0
        for key,val in optimiseParams.p.iteritems():
            self.otherParams.p[key] = val
            self.storedOptimiseNames[count] = key
            count += 1
        self.allParams = dict(self.modelParams.p.items() + self.otherParams.p.items())
        self.currentStatus = 1

    def setPricingParams(self, index = 0):
        pricingParamsSetToUse = self.pricingParamsSets[index]
        for key,val in pricingParamsSetToUse.p.iteritems():
            if not key == 'price' and not key == 'weight':
                self.otherParams.p[key] = val
        self.targetPrice = pricingParamsSetToUse.p['price']
        self.targetWeight = pricingParamsSetToUse.p['weight']
        self.allParams = dict(self.modelParams.p.items() + self.otherParams.p.items())
        
    def preComputations(self):
        self.preComputationVariables = []

    def getPrice(self):
        pass

    def updateOptimiseParams(self, changedOptimiseParams = []):
        for idx in range(len(changedOptimiseParams)):
            self.otherParams.p[self.storedOptimiseNames[idx]] = changedOptimiseParams[idx]
        self.allParams = dict(self.modelParams.p.items() + self.otherParams.p.items())
